﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VirtualOperator
{
    public class UserConnection
    {
        public List<VirtualNetwork.Link> links;
        private int capicity;
        private int id;
        private NwTTP sourceNwTTP;
        private NwTTP targetNwTTP;
        public int Capacity { get { return capicity; } }
        public int ID { get { return id; } set { id = value; } }

        public UserConnection(NwTTP sourceNwTTP, NwTTP targetNwTTP, List<VirtualNetwork.Link> links, int capicty)
        {
            this.links = links;
            this.capicity = capicty;
            this.sourceNwTTP = sourceNwTTP;
            this.targetNwTTP = targetNwTTP;
        
        }
        public UserConnection(List<VirtualNetwork.Link> links, int capicty)
        {
            this.links = links;
            this.capicity = capicty;

        }
        public Dictionary<int, VirtualNetwork.Matrix> MatrixPath 
        { 
           get{ 
              Dictionary<int, VirtualNetwork.Matrix> nodes = new Dictionary<int, VirtualNetwork.Matrix>();
              foreach (VirtualNetwork.Link link in links)
              {
                  nodes.Add(link.Source.ID, link.Source);
              }
              nodes.Add(links.Last().Target.ID, links.Last().Target);
              return nodes;
           }
        }
        public VirtualNetwork.Matrix SourceMatrix { get { return links.First().Source; } }
        public VirtualNetwork.Matrix TargetMatrix { get { return links.Last().Target; } }
        public NwTTP SourceNwTTP { get { return sourceNwTTP;  } }
        public NwTTP TargetNwTTP { get { return targetNwTTP;  } }


        public override string ToString()
        {

            return SourceMatrix.Name + " ----> " + TargetMatrix.Name + ", Capacity: " + capicity;
        }

        public void RemovePath(){
            foreach (VirtualNetwork.Link link in links)
            {
                link.Capacity += capicity;
            }
        }


        public void SetPath()
        {
            foreach (VirtualNetwork.Link link in links)
            {
                link.Capacity -= capicity;
            }
        }
    }
}
